<?php
require_once(dirname(__FILE__)."/../inc/common.php");
/*******************************************************************************************
'*******************************************************************************************/
if (newsparamset==0 || newsrunMode=="forgedStatic"){
	$paras = replaceStr(QUERY_STRING,newsFileSuffix, "");
	if (strpos($paras, "-") > 0) {
		$parasArray = explode("-",$paras); $id = $parasArray[0]; $page = $parasArray[1];
    } else {
	    $id = $paras; $page = 1;
	}
}else{
	$id=getForm(newsparamid,"both");$page=getForm(newsparamid,"both");
}

if (empty($id)) {
	echoSaveStr("null");exit();
} else {
	if(!is_numeric($id)) { echoSaveStr("safe");exit(); } else { $id=intval($id); }
}
if (empty($page)) {
	$page=1;
} else {
	if (is_numeric($page)) { $page = intval($page); } else { echoSaveStr("safe");exit();}
}
echoContent($id);

function echoContent($vId) {
	global $t1,$page,$currentId,$currentEnname,$currentDatetime;
	$row = DB::fetch_first("SELECT m_id,m_title,m_type,m_vid,m_pic,m_hit,m_author,m_content,m_color,m_addtime,m_from,m_outline,m_commend,m_letter,m_keyword,m_digg,m_tread,m_entitle,m_datetime,m_note,m_score FROM ".DB::table('news')." WHERE m_id='$vId' AND m_recycle=0");
	if (!is_array($row)) { OutNotFound("news");}
	$vType = $row['m_type'];$venname = $row['m_entitle'];$vdatetime = $row['m_datetime'];
	if (strpos(" ,".getHideNewsTypeIDS().",",",".$vType.",") > 0) { OutNotFound("news");}
	$y = explode(",", getNewsTypeNameTemplateArrayOnCache(intval($vType)));$z = ifthen(empty($y[4]), "news.html", $y[4]);$x = DJCMS_TEMPLATE.$z;
	$contentLink = getNewsArticleLink($vType,$vId,$venname,$vdatetime,"link");$typeText = getNewsTypeTextOnCache($vType);
	$currentId=$vId;djcms::$currentTypeId=$vType;$currentEnname=$venname;$currentDatetime=$vdatetime;$typeFlag = "parse_article_" ;$cacheName = $typeFlag.$vType;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseContentPart($x);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseContentPart($x);
	}
	djcms::paresPreNextNews($vId, $vType);
	djcms::parseNews($row);
	$content = replaceStr(djcms::$content,"{news:id}",$row['m_id']);
	$content = replaceStr($content,"{news:encodetitle}",urlencode($row['m_title']));
	$content = replaceStr($content,"{news:note}",parseNewsNote($row['m_note']));
	$content = replaceStr($content,"{news:nolinkkeywords}",$row['m_keyword']);
	if (isExistStr($content,"{news:keywords}")) $content = replaceStr($content,"{news:keywords}",replaceStr(getKeywordsList($row['m_keyword'],"&nbsp;&nbsp;"),"search.php","so.php"));
	if (!empty($row['m_pic'])) {
		if (strpos(' '.$row['m_pic'], 'http://') > 0) {
		    $content = replaceStr($content,"{news:pic}",$row['m_pic']);
		} else {
		    $content = replaceStr($content,"{news:pic}","/".sitePath.$row['m_pic']);
		}
	} else {
		$content = replaceStr($content,"{news:pic}","/".sitePath."pic/nopic.gif");
	}
	$content = replaceStr($content,"{news:author}",$row['m_author']);
	$content = replaceStr($content,"{news:from}",$row['m_from']);
	$content = replaceStr($content,"{news:outline}",$row['m_outline']);
	$content = replaceStr($content,"{news:diggnum}",$row['m_digg']);
	$content = replaceStr($content,"{news:treadnum}",$row['m_tread']);
	$content = replaceStr($content,"{news:scorenum}",$row['m_score']);
	$content = replaceStr($content,"{news:commend}",$row['m_commend']);
	$content = replaceStr($content,"{news:link}",$contentLink);
	$content = replaceStr($content,"{news:url}","http://".siteUrl.$contentLink);
	djcms::$content = replaceStr($content,"{news:textlink}",$typeText."&nbsp;&nbsp;&raquo;&nbsp;&nbsp;".$row['m_title']);
	if (isExistStr(djcms::$content,"{news:subcontent}") || isExistStr(djcms::$content,"{news:subtitle}") || isExistStr(djcms::$content,"{news:subpagenumber")){
			$z=parseSubpage($row['m_content']);
			$content = replaceStr(djcms::$content,"{news:subtitle}",$z[1]);
			$content = replaceStr($content,"{news:subcontent}",$z[2]);
			$x=StrSlice($content,"{news:subpagenumber","}");
			$slidewarr = djcms::parseAttr($z);
			$y = $slidewarr['len'];if (empty($y)){ $y=10; }else{ $y=$y;}
			if ($z[0]>0){
				$y=pageNumberLinkInfo($page,$y,$z[0],"newssubpage",$z[0]);
			}else{
				$y="";
			}
			djcms::$content = replaceStr($content,"{news:subpagenumber".$x."}",$y);
	}
	djcms::parseIf();
	echo replaceStr(djcms::$content,"{yh:runinfo}",getRunTime($t1)) ;
}

function parseSubpage($Des){
	global $page;
	$x=split("#p#",$Des);$ret=array(count($x),"","");$i=$page-1;
	if ($i>-1 && $ret[0]>=$i){
		if (!isExistStr($x[$i],"#e#")) $x[$i]="#e#".$x[$i];
		$y=split("#e#",$x[$i]);$ret[1]=$y[0];$ret[2]=$y[1];
    }
	$ret[0]=$ret[0];
	return $ret;
}

function parseContentPart($x) {
	djcms::$content=loadFile($x);
	djcms::parseNewsPageSpecial();
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	$typename = explode(",", getNewsTypeNameTemplateArrayOnCache(djcms::$currentTypeId));
	djcms::$content = replaceStr(replaceCurrentTypeId(djcms::$content),"{news:typeid}",djcms::$currentTypeId);
	if (isExistStr(djcms::$content,"{news:upid}")) djcms::$content = replaceStr(djcms::$content,"{news:upid}",getNewsTypeUpid2(djcms::$currentTypeId));
	if (isExistStr(djcms::$content,"{news:typename}")) djcms::$content = replaceStr(djcms::$content,"{news:typename}",$typename[0]);
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
}
?>